<template>
  <div class="document">
    <el-row>
      <el-col :span="4" class="left">
        <h2>怀才可遇用户文档</h2>
        <!-- <div v-for="item in menuData" :key="item.documentInfoId">
          <div v-if="item.children.length > 0" class="title">{{ item.title }}</div>
          <ul v-else>
            <li @click="getDetail(item.documentInfoId)">{{ item.title }}</li>
          </ul>
          <ul>
            <li v-for="i in item.children" :key="i.documentInfoId" @click="getDetail(i.documentInfoId)">{{ i.title }}</li>
          </ul>
        </div> -->
        <el-scrollbar wrap-class="scrollbar-wrapper">
          <!-- <el-tree :data="menuData" :props="defaultProps" node-key="id" @node-click="getDetail"></el-tree> -->
          <el-menu
            :default-active="documentId"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            @select="getDetail">
            <template v-for="item in menuData">
              <el-menu-item v-if="item.children" :index="item.id">{{ item.name }}</el-menu-item>
              <el-submenu v-for="i in item.children" :key="i.id" :index="i.id">
                <el-menu-item :index="i.id">{{ i.name }}</el-menu-item>
              </el-submenu>
            </template>
          </el-menu>
        </el-scrollbar>
      </el-col>
      <el-col :span="20" class="right">
        <div>
          <h1>{{ detailInfo.title }}</h1>
        </div>
        <div class="content" v-html="detailInfo.htmlContent"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
// import { documentList, documentDetail } from "@/api/document";
import request from '@/utils/request'
export default {
  name: 'Document',
  data () {
    return {
      menuData: [
      ],
      detailInfo: {},
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      documentId: '0'
    }
  },
  computed: {

  },
  created() {
    this.getDocumentList()
    if (this.$route.query.id) {
      this.documentId = this.$route.query.id
      this.getDetail(this.documentId)
    }
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    },
    getDocumentList() {
      request.get('/xsy-service-web/WebDocontent/get').then(res => {
        console.log(res.data)
        this.menuData = res.data
      })
    },
    getDetail(id) {
      request.get('/xsy-service-web/WebDocontent/get/'+id).then(res => {
        console.log(res.data)
        this.detailInfo = res.data
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.document {
  height: calc(100vh - 80px);
  font-size: 14px;
  .el-row {
    height: 100%;
  }
  .title {
    font-weight: 600;
  }
  .left {
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    h2 {
      height: 70px;
      margin: 0;
      background-color: #fff;
      padding: 20px 20px;
      border: 1px solid #fff;
      border-left: none;
      border-right: none;
    }
    .el-scrollbar {
      min-height: calc(100vh - 150px);
      background-color: #fff;
      .el-menu {
        border: none;
      }
    }
  }
  .right {
    margin-left: 340px;
    height: 100%;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    h1 {
      font-weight: 200;
      font-size: 30px;
      padding-left: 40px;
    }
  }
  .content {
    background-color: #fff;
    height: calc(100% - 85px);
    padding: 50px;
    padding-top: 0;
    overflow-y: scroll;
  }
}
</style>

